package com.bristua.sms.tencent;

import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import com.github.qcloudsms.httpclient.HTTPException;
import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * Created by Administrator on 2019/4/27.
 */
@Component
public class SmsUtil {
//
    private static final int appid=1400206035;
    private static final String appkey="b38a02bb201d3d82dab217f3dac9d550";

    private static final Logger logger = LoggerFactory.getLogger(SmsUtil.class);

//    private static final int appid=1400009099;
//    private static final String appkey="9ff91d87c2cd7cd0ea762f141975d1df37481d48700d70ac37470aefc60f9bad";

    @Async
    public  void smsSend(String phone,String code) {
        try {
            String[] params = new String[2];
            params[0] = code;
            params[1] = "10";
            SmsSingleSender ssender = new SmsSingleSender(appid, appkey);
            SmsSingleSenderResult result = ssender.sendWithParam("86", phone,
                    322043, params ,"福州凤天网络科技有限公司", "", "");  // 签名参数未提供或者为空时，会使用默认签名发送短信
            logger.info("验证码:"+code+",手机号:"+phone+","+result);
        } catch (HTTPException e) {
            // HTTP响应码错误
            e.printStackTrace();
        } catch (JSONException e) {
            // json解析错误
            e.printStackTrace();
        } catch (IOException e) {
            // 网络IO错误
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        SmsUtil smsUtil = new SmsUtil();
        smsUtil.smsSend("15080453418","123458");
    }
}
